// 个人简介界面
import React from 'react';
import ReactDOM from 'react-dom';
import { Link } from 'react-router';
import ReactScrollbar from 'react-scrollbar-js';
require("./home.css");

class Intro extends React.Component{

    constructor(){
        super();
        this.state = {
            query: [],
            gender:'',
            birth:'',
            place:'',
            education:'',
            major:'',
            address:'',
            studyExp: [],
            jobExp: [],
            monthSum: [],
            yearSum: []
        }
    }

    componentWillMount(){
        this.FetchUserData();
        this.FetchInfoData();
        // this.FetchMonth();
        // this.FetchYear();
    }

    //将当前选中的用户的user_id，company_id提交到服务器然后setState到query里面
    FetchUserData(){
        fetch("http://121.196.202.247:1010/select_user/?user_id="+this.props.location.query.selectUser, {
            method: "GET",
            headers: {
                'Accept': 'application/json',
                "Content-Type": "application/json; charset=utf-8"
            },
        }) .then((response) => response.json())
            .then((responseText) => {
                this.setState({query:responseText});
                console.log("1111111111"+JSON.stringify(responseText));
            }).catch((error) => {alert(error+"连接职信服务器失败，请查看网络连接状态并刷新页面！")});
    }

    // 将当前选中的用户的resume_user_id提交到服务器返回信息
    FetchInfoData(){
        fetch("http://121.196.202.247:1010/resume/?resume_user_id="+this.props.location.query.selectUser, {
            method: "GET",
            headers: {
                'Accept': 'application/json',
                "Content-Type": "application/json; charset=utf-8"
            },
        }) .then((response) => response.json())
            .then((responseText) => {
                if(responseText.BasicInformation == 'Basic Information Null!'){
                    alert("该用户还未填写过个人基本资料以及过往经历...");
                }else{
                    this.setState({gender: responseText.BasicInformation[0]['1']});
                    this.setState({birth: responseText.BasicInformation[1]['2']});
                    this.setState({place: responseText.BasicInformation[2]['3']});
                    this.setState({education: responseText.BasicInformation[3]['4']});
                    this.setState({major: responseText.BasicInformation[4]['5']});
                    this.setState({address: responseText.BasicInformation[5]['6']});
                    this.setState({studyExp: responseText.StudyExperience});
                    this.setState({jobExp: responseText.JobExperience});
                }
            }).catch((error) => {alert(error+"连接职信服务器失败，请查看网络连接状态并刷新页面！")});
    }

    // 将当前选中的用户的monthsum_user_id提交到服务器返回信息
    FetchMonth(){
        console.log(this.props.location.query.selectUser+"aa");
        console.log("http://121.196.202.247:1010/t_monthsummary/?monthsum_user_id="+this.props.location.query.selectUser);
        fetch("http://121.196.202.247:1010/t_monthsummary/?monthsum_user_id="+this.props.location.query.selectUser, {
            method: "GET",
            headers: {
                'Accept': 'application/json',
                "Content-Type": "application/json; charset=utf-8"
            },
        }) .then((response) => response.json())
            .then((responseText) => {
                console.log(responseText);
                console.log(JSON.stringify(responseText));
            }).catch((error) => {alert(error+"连接职信服务器失败，请查看网络连接状态并刷新页面！")});
    }

    // 将当前选中的用户的yearsum_user_id提交到服务器返回信息
    FetchYear(){
        fetch("http://121.196.202.247:1010/t_yearsummary/?yearsum_user_id="+this.props.location.query.selectUser,{
            method: "GET",
            headers: {
                'Accept': 'application/json',
                "Content-Type": "application/json; charset=utf-8"
            },
        }) .then((response) => response.json())
            .then((responseText) => {
                if(responseText.fail_info == 'can not find this user in yearsummary!'){
                    alert("该用户未有月度评价信息...");
                }else{
                    this.setState({yearSum: responseText.information});
                }
            }).catch((error) => {alert(error+"连接职信服务器失败，请查看网络连接状态并刷新页面！")});
    }



    render(){
        const style = {
            scroll:{
                width: "410px",
                height: "150px",
            }
        };

        const studyExp = [];
        console.log(this.state.studyExp+"xyh");
        if(this.state.studyExp != ''){
            studyExp.length = 0;
            for(let i=0;i<this.state.studyExp.length;i++){
                studyExp.push(
                    <div>
                        <p>{this.state.studyExp[i][i+1]}</p>
                        <hr/>
                    </div>
                );
            }
        }else{
            studyExp.length = 0;
            studyExp.push(
                <div>
                    <p>该用户还未填写过往学习经历...</p>
                </div>
            );
        }

        const jobExp = [];
        if(this.state.jobExp != ''){
            jobExp.length = 0;
            for(let i=0;i<this.state.jobExp.length;i++){
                jobExp.push(
                    <div>
                        <p>{this.state.jobExp[i][i+1]}</p>
                        <hr/>
                    </div>
                );
            }
        }else{
            jobExp.length = 0;
            jobExp.push(
                <div>
                    <p>该用户还未填写过往工作经历...</p>
                </div>
            );
        }

        const monthSum = [];
        if(this.state.monthSum != ''){
            monthSum.length = 0;
            for(let i=0;i<this.state.monthSum.length;i++){
                monthSum.push(
                    <div>
                        <p>{this.state.monthSum[i].month_summary_date}</p>
                        <hr/>
                    </div>
                );
            }
        }else{
            monthSum.length = 0;
            monthSum.push(
                <div>
                    <p>该用户还未有月度评价...</p>
                </div>
            );
        }

        const yearSum = [];
        if(this.state.yearSum != []){
            yearSum.length = 0;
            console.log(this.state.yearSum.length);
            for(let i=0;i<this.state.yearSum.length;i++){
                yearSum.push(
                    <p>{this.state.yearSum[i]}</p>
                );
            }
        }else{
            yearSum.length = 0;
            yearSum.push(
                <div>
                    <p>该用户还未有年度评价...</p>
                </div>
            );
        }

        if(this.state.query.length == 1){
            return(
                <div className="intro_box" >
                    <div className="basic_info">
                        <h4>基本信息：</h4>
                        <p>姓名：<input type="text" value={this.state.query[0].user_name} className="basic_info_tab"/></p>
                        <p>性别：<input type="text" className="basic_info_tab" value={this.state.gender}/></p>
                        <p>出生年月：<input type="text" value={this.state.birth}/></p>
                        <p>籍贯：<input type="text" className="basic_info_tab" value={this.state.place}/></p>
                        <p>学历：<input type="text" className="basic_info_tab" value={this.state.education}/></p>
                        <p>专业：<input type="text" className="basic_info_tab" value={this.state.major}/></p>
                        <p>家庭住址：<input type="text" value={this.state.address}/></p>
                        <p>联系方式：<input type="text" value={this.state.query[0].user_phone}/></p>
                    </div>
                    
                    <div className="study_exp">
                        <h4>学习经历：</h4>
                        <div className="study_exp_box">
                            <ReactScrollbar style={style.scroll}>
                                <div>
                                    <hr/>
                                    {studyExp}
                                    <hr/>
                                </div>
                            </ReactScrollbar>
                        </div>
                    </div>
                    
                    <div className="job_exp">
                        <h4>工作经历：</h4>
                        <div className="job_exp_box">
                            <ReactScrollbar style={style.scroll}>
                                <div>
                                    <hr/>
                                    {jobExp}
                                    <hr/>
                                </div>
                            </ReactScrollbar>
                        </div>
                    </div>

                    <div className="monthly_eva">
                        <h4>月度评价：</h4>
                        <div className="month_box">
                            <ReactScrollbar style={style.scroll}>
                                <div>
                                    <hr/>
                                    {monthSum}
                                    <hr/>
                                </div>
                            </ReactScrollbar>
                        </div>
                    </div>

                    <div className="annual_eva">
                        <h4>年度评价：</h4>
                        <div className="annual_box">
                            <ReactScrollbar style={style.scroll}>
                                <div>
                                    <hr/>
                                    {yearSum}
                                    <hr/>
                                </div>
                            </ReactScrollbar>
                        </div>
                    </div>
                    <Link to='/home_query_hr'><input type="button" value="返回" className="intro_back"/></Link>
                </div>
            );
        }else{
            return(
                <p>正在加载中......</p>
            );
        }
    }
}

export default Intro;